<?php

	
	

	
	require_once "header.php";
	$cConfiguration = new CConfiguration;
	
	
	$curDay = date ("h:i:s m-d-Y ",mktime(date('h') +7 ,date('i'), date('s'), date("m")  , date("d") , date("Y")))."(GMT + 7:00  Bangkok, HaNoi, Jarjata)";
		
	
	$mainContent = "";
	if(isset($_GET['jmp']))
	{
		$com = $_GET['jmp'];
		$action = substr($_GET['to'],3);
		
		
/* ---------------------------------------------
*
*				PROFILE				
*
------------------------------------------------*/	
		
		
		if($com ==="profile" && $action==="out")
		{
				unset($_SESSION['username']);
				unset($_SESSION['idUser']);
				
				
				if(isset($_SESSION['lastLogin']))
				{
					//echo date('h:i:s m:d:Y',$_SESSION['lastLogin']);
					$cConfiguration -> CConfigurationUpdateValue(2,$_SESSION['lastLogin']);
					unset($_SESSION['lastLogin']);

				}
				
				if(isset($_SESSION['lastModify']))
				{
					$cConfiguration ->CConfigurationUpdateValue(3,$_SESSION['lastModify']);
					unset($_SESSION['lastModify']);
				}
				
							
				echo '<script language="javascript">window.location.href="index.php"</script>'; 
				return;
		}
		
		if($com === "profile" && $action === "pas")
		{
			//if(isset() && isset())
			$mainContent = '<form action="processUser.php" method="post" name="form1">
                        	<div id="content2">
                        	<table border="0" width="90%" style="position:relative" align = "center" >
                            	<tr>
                                	<td colspan="2" align="left" valign="middle" height="50px"> 
                                     <img src="images/security_f2.png" style="float:left" border="0"/>
                                    <span class="mystyle1"> Change Password </span>		 </td>
                                </tr>
                        		<tr>
                                	<td width="30%">
										<span class="mystyle2">Current Password: </span>
                                    </td>
                                    <td width="60%">
                                    	<input id="input1" type="password" name="tf_curpass" value="">
                                    </td>
                                </tr>
                                <tr>
                                	<td><span class="mystyle2">New Password:<span>
                                    </td>
                                    <td>
                                    	<input id="input1" type="password" name="tf_newpassword" >
                                    </td>
                                </tr>
								 <tr>
                                	<td><span class="mystyle2">Retype New Password:<span>
                                    </td>
                                    <td>
                                    	<input id="input1" type="password" name="tf_newretypepassword" >
                                    </td>
                                </tr>
                                <tr align="center">
                                	<td colspan="2" height="50px">
                                    	<input id="input2"  type="submit" name="btn_ok" value="  OK  ">
                                        <input id="input2" name="btn_cancel" type="submit" value="  Cancel  " >
                                    </td>
                                </tr>
                        	</table>
                        </div>
						<input type="hidden" name = "hUserAction" value="pas">
						</form>';
			
		}
		
		if($com ==="profile" && $action ==="pro")
		{
			$user = new CUsers;
			$detailUser = $user->CUsersDetail($_SESSION['idUser']);
			
			if(is_array($detailUser))
			{
				
				if($detailUser['gender'] ==1)
				{
					$rdbtnGender ='  <label><input type="radio" name="rdbtn_gender" value="1" checked="checked" >Male</label>
									 -- 
									<label><input type="radio" name="rdbtn_gender" value="0" > Female </label>
									';
				}
				else
				{
					$rdbtnGender =' <label> <input type="radio" name="rdbtn_gender" value="1"  > Male</label>
								 -- 
								<label> <input type="radio" name="rdbtn_gender" value="0" checked="checked"> Female</label>
								';
				}
				
				
				
				$mainContent = '<form action="processUser.php" method="post" name="form1">
								<div id="content2">
								<table border="0" width="90%" style="position:relative" align = "center" >
									<tr>
										<td colspan="2" align="left" valign="middle" height="50px"> 
										 <img src="images/profile.png" style="float:left" border="0"/>
										<span class="mystyle1"> Update Profile </span>		 </td>
									</tr>
									<tr>
										<td width="30%">
											<span class="mystyle2">Username </span>
										</td>
										<td width="60%">
											<input disabled="disabled" id="input1" style="background:#CCCCCC" readonly type="text" name="tf_username" value="'.$detailUser['username'].'">
										</td>
									</tr>
									<tr>
										<td><span class="mystyle2">Last name<span>
										</td>
										<td>
											<input id="input1" type="text" name="tf_lastname" value="'.$detailUser['lastname'].'">
										</td>
									</tr>
									 <tr>
										<td><span class="mystyle2">First name<span>
										</td>
										<td>
											<input id="input1" type="text" name="tf_firstname" value="'.$detailUser['firstname'].'" >
										</td>
									</tr>
									 <tr>
										<td valign="top"><span class="mystyle2">Gender <span>
										</td>
										<td>
											'.$rdbtnGender.'
										</td>
									</tr>
									
									 <tr>
										<td><span class="mystyle2">Birthday <span>
										</td>
										<td>
											<input id="input1" type="text" name="tf_birthday" value="'.$detailUser['birthday'].'" >
										</td>
									</tr>
									
									<tr>
										<td><span class="mystyle2">Cell phone <span>
										</td>
										<td>
											<input id="input1" type="text" name="tf_cellphone" value="'.$detailUser['cellphone'].'" >
										</td>
									</tr>
									
									<tr>
										<td valign="top"><span class="mystyle2">Address <span>
										</td>
										<td>
											<textarea cols="50" rows="3" id="input1"  name="tf_address" >'.$detailUser['address'].'</textarea>
										</td>
									</tr>
									<tr align="center">
										<td colspan="2" height="50px">
											<input id="input2"  type="submit" name="btn_ok" value="  OK  ">
											<input id="input2" name="btn_cancel" type="submit" value="  Cancel  " >
										</td>
									</tr>
								</table>
							</div>
							<input type="hidden" name = "hUserAction" value="pro">
							</form>';
			}
			else
			{
				echo '<script language="javascript">window.location.href="main.php"</script>';  	
			}
		
		}
/* ---------------------------------------------
*
*				CONTACT					
*
------------------------------------------------*/	

		//************************************************
		// edit Contact
		//************************************************
		if($com ==="contact" && $action ==="edi")
		{
			$cDetail = new CSiteInfo;
			
			$contact = $cDetail -> CSiteInfoDetail(2);
			
			if($contact['status'] ==1)
			{
				$rdbtnStatus ='  <label><input type="radio" name="rStatus" value="1" checked="checked" >Active</label>
								<br>
								<label><input type="radio" name="rStatus" value="0" > Inactive </label>
								';
			}
			else
			{
				$rdbtnStatus =' <label><input type="radio" name="rStatus" value="1"  >Active </label>
							<br>
							<label><input type="radio" name="rStatus" value="0" checked="checked">Inactive </label>
							';
			}
			
			if(is_array($contact))
			{
				$mainContent = '<form action="processACT.php" method="post" name="form1">
								<script type="text/javascript">
									bkLib.onDomLoaded(function() {
									new nicEditor({maxHeight : 400}).panelInstance("area");
									});
								</script>
								<div id="content2">
									<table border="0" width="90%" style="position:relative" align = "center" >
									<tr>
										<td colspan="2" align="left" valign="middle" height="50px"> 
										 <img src="images/profile.png" style="float:left" border="0"/>
										<span class="mystyle1"> Edit Contact</span>		 </td>
									</tr>
																	
									<tr>
										<td valign="top" colspan="2">
											<span class="mystyle2">Content <span>
											<br /> &nbsp;
										</td>
									</tr>
									<tr>	
										<td colspan="2">                                    	
											<textarea cols="70" name="tf_content" id="area" style="height: 400px;">'.$contact['content'].'</textarea>                         </td>
									</tr>
									
									<tr>
										<td><span class="mystyle2">Status <span>
										</td>
										<td>
											'.$rdbtnStatus.'
		
										</td>
									</tr>
									
									<tr align="center">
										<td colspan="2" height="50px">
											<input id="input2"  type="submit" name="btn_ok" value="  OK  ">
											<input id="input2" name="btn_cancel" type="submit" value="  Cancel  " >
										</td>
									</tr>
			 
									</table>
								</div>
								<input type="hidden" name="tf_type_processACT" value="2">
								<input type="hidden" name="tf_name" value="contact">
								</form>';
								
			}
			else
			{
				echo '<script language="javascript">window.location.href="main.php"</script>';  	
			}
		}
/* ---------------------------------------------
*
*				ABOUT					
*
------------------------------------------------*/	
		
		//************************************************
		// edit About
		//************************************************
		if($com ==="about" && $action ==="edi")
		{
			
			$cDetail = new CSiteInfo;
			
			$about = $cDetail -> CSiteInfoDetail(1);
			
			if($about['status'] ==1)
			{
				$rdbtnStatus ='  <label><input type="radio" name="rStatus" value="1" checked="checked" >Active</label>
								<br>
								<label><input type="radio" name="rStatus" value="0" > Inactive </label>
								';
			}
			else
			{
				$rdbtnStatus =' <label><input type="radio" name="rStatus" value="1"  >Active </label>
							<br>
							<label><input type="radio" name="rStatus" value="0" checked="checked">Inactive </label>
							';
			}
			
			if(is_array($about))
			{
				$mainContent = '<form action="processACT.php" method="post" name="form1">
								<script type="text/javascript">
									bkLib.onDomLoaded(function() {
									new nicEditor({maxHeight : 400}).panelInstance("area");
									});
								</script>
								<div id="content2">
									<table border="0" width="90%" style="position:relative" align = "center" >
									<tr>
										<td colspan="2" align="left" valign="middle" height="50px"> 
										 <img src="images/profile.png" style="float:left" border="0"/>
										<span class="mystyle1"> Edit About Us Content</span>		 </td>
									</tr>
																	
									<tr>
										<td valign="top" colspan="2">
											<span class="mystyle2">Content <span>
											<br /> &nbsp;
										</td>
									</tr>
									<tr>	
										<td colspan="2">                                    	
											<textarea cols="70" name="tf_content" id="area" style="height: 400px;">'.$about['content'].'</textarea>                         </td>
									</tr>
									
									<tr>
										<td><span class="mystyle2">Status <span>
										</td>
										<td>
											'.$rdbtnStatus .'
		
										</td>
									</tr>
									
									<tr align="center">
										<td colspan="2" height="50px">
											<input id="input2"  type="submit" name="btn_ok" value="  OK  ">
											<input id="input2" name="btn_cancel" type="submit" value="  Cancel  " >
										</td>
									</tr>
			 
									</table>
								</div>
								<input type="hidden" name="tf_type_processACT" value="1">
								<input type="hidden" name="tf_name" value="about">
								</form>';
			}
			else
			{
				echo '<script language="javascript">window.location.href="main.php"</script>';  	
			}
		}
/* ---------------------------------------------
*
*				TERM
*
------------------------------------------------*/	

		//************************************************
		// edit TERM
		//************************************************
		if($com ==="term" && $action ==="edi")
		{
		
			
			$cDetail = new CSiteInfo;
			
			
			
			
			$term = $cDetail -> CSiteInfoDetail(3);
			
			
			
			if(is_array($term))
			{
			
				if($term['status'] ==1)
				{
					$rdbtnStatus ='  <label><input type="radio" name="rStatus" value="1" checked="checked" >Active</label>
									<br>
									<label><input type="radio" name="rStatus" value="0" > Inactive </label>
									';
				}
				else
				{
					$rdbtnStatus =' <label><input type="radio" name="rStatus" value="1"  >Active </label>
								<br>
								<label><input type="radio" name="rStatus" value="0" checked="checked">Inactive </label>
								';
				}			
				$mainContent = '<form action="processACT.php" method="post" name="form1">
								<script type="text/javascript">
									bkLib.onDomLoaded(function() {
									new nicEditor({maxHeight : 400}).panelInstance("area");
									});
								</script>
								<div id="content2">
									<table border="0" width="90%" style="position:relative" align = "center" >
									<tr>
										<td colspan="2" align="left" valign="middle" height="50px"> 
										 <img src="images/profile.png" style="float:left" border="0"/>
										<span class="mystyle1"> Edit Terms of Use</span>		 </td>
									</tr>
																	
									<tr>
										<td valign="top" colspan="2">
											<span class="mystyle2">Content <span>
											<br /> &nbsp;
										</td>
									</tr>
									<tr>	
										<td colspan="2">                                    	
											<textarea cols="70" name="tf_content" id="area" style="height: 400px;">'.$term['content'].'</textarea>                         </td>
									</tr>
									
									<tr>
										<td><span class="mystyle2">Status <span>
										</td>
										<td>
											'.$rdbtnStatus.'
		
										</td>
									</tr>
									
									<tr align="center">
										<td colspan="2" height="50px">
											<input id="input2"  type="submit" name="btn_ok" value="  OK  ">
											<input id="input2" name="btn_cancel" type="submit" value="  Cancel  " >
										</td>
									</tr>
			 
									</table>
								</div>
								<input type="hidden" name="tf_type_processACT" value="3">
								<input type="hidden" name="tf_name" value="terms">
								</form>';
			}
			else
			{
				echo '<script language="javascript">window.location.href="main.php"</script>';  	
			}
		}


/* ---------------------------------------------
*
*				CATEGORY	&& TYPE				
*
------------------------------------------------*/


		

		if($com ==="categories" && $action ==="add")
		{
			//************************************************
			// add Catergory
			//************************************************
			require_once "loadAddCategory.php";
		}

		
		if($com ==="types" && $action ==="add")
		{
			
			//************************************************
			// add Type
			//************************************************	
		
			require_once "loadAddType.php";
		}
		
		if($com === "types" && $action === "edi")
		{
			
			//************************************************
			// add Type
			//************************************************
			if(isset($_GET['idbpos']))	
			{	
				require_once "loadEditType.php";
			}
			else
			{
				echo '<script language="javascript">window.location.href="main.php"</script>';  	
			}
			
			
			
		}
		
		
		if($com === "types" && $action ==="del")
		{
			if(isset($_GET['idbpos']))
			{
				require_once "loadDelType.php";				
			}
			else
			{
				echo '<script language="javascript">window.location.href="main.php"</script>';  	
			}
				
		}


		if($com === "categories" && $action === "edi")
		{
			//************************************************
			// edit Category
			//************************************************
			if(isset($_GET['idbpos']))
			{
				require_once "loadEditCategory.php";				
			}
			else
			{
				echo '<script language="javascript">window.location.href="main.php"</script>';  	
			}			
			
		}
		
		
		if($com === "categories" && $action ==="del")
		{
			//************************************************
			// delete Category
			//************************************************
			if(isset($_GET['idbpos']))
			{
				require_once "loadDelCategory.php"	;
			}
			else
			{
				echo '<script language="javascript">window.location.href="main.php"</script>';  	
			}
		}
		
		if($com =="catetype" && $action =="view")
		{
			//************************************************
			// view Category and Type
			//************************************************
			require_once 'loadListCateType.php';
		}
		
		
/* ---------------------------------------------
*
*				ITEMS					
*
------------------------------------------------*/
		
	
		
		if($com ==="items" && $action ==="edi")
		{		
			//************************************************
			// edit Items
			//************************************************
			require_once "loadEditItem.php";				
		}
		
		
		
		
		if($com ==="items" && $action ==="view")
		{	
			//************************************************
			// view List of Items
			//************************************************	
			require_once "loadListItem.php";							
		}
		
		
		if($com ==="items" && $action ==="del")
		{		
			//************************************************
			// del Items
			//************************************************
			require_once "loadDelItem.php";
			
		}
		
		
		if($com ==="items" && $action ==="add")
		{		
			//************************************************
			// add Items
			//************************************************
				require_once "loadAddItem.php";
		}
		
/* ---------------------------------------------
*
*				ARTICLES					
*
------------------------------------------------*/	


		
		if($com ==="article" && $action ==="add")
		{
			
			$mainContent = '
			<form action="processArticle.php" method="post" name="form1">
			
			<script type="text/javascript">
								bkLib.onDomLoaded(function() {
								new nicEditor({maxHeight : 200}).panelInstance("area");
								});
							</script>
			<div id="content3">
                        	<table border="0" width="95%" style="position:relative" align = "center" >
                            	<tr>
                                	<td colspan="2" align="left" valign="middle" height="50px"> 
                                     	<img src="images/security_f2.png" style="float:left" border="0"/>
                                    	<span class="mystyle1"> Add more Articles </span>		 
									</td>
                                </tr>
                        		<tr>
                                	<td width="20%">
										<span class="mystyle2">Title </span>
                                    </td>
                                    <td width="80%">
                                    	<input id="input3" type="text" name="tf_title" value="">
                                    </td>
                                </tr>
                                <tr>
                                	<td height="40px" colspan="2"><span class="mystyle2" ">Content</span>
                                    </td>
                                </tr>
								 <tr>
                                	<td colspan="2" style="background:#fff">
										<textarea cols="72" name="tf_content" id="area" style="height: 200px;">	Some Initial Content was in this textarea</textarea>
                                    </td>
                                    
                                </tr>
								 <tr height="40px">
                                	<td width="20%"><span class="mystyle2">Source</span>
                                    </td>
                                    <td width="80%">
										<input id="input3" type="text" name="tf_source" value="">
                                    </td>
                                </tr>
                                <tr align="center">
                                	<td colspan="2" height="50px">
                                    	<input id="input2"  type="submit" name="btn_ok" value="  OK  ">
                                        <input id="input2" name="btn_cancel" type="submit" value="  Cancel  " >
                                    </td>
                                </tr>
                        	</table>
                        </div> </form>';
		}
		
		

	}
	else
	{
		
		$notification = "";
		if(isset($_GET['notification']))
		{
			$notification = constant($_GET['notification']);
		}
		
		//echo "Please wait for a minutes...";
		$cConfiguration = new CConfiguration ;
		
		$numOfView = $cConfiguration ->CConfigurationDetail(1);
		$detailLastLogin = $cConfiguration ->CConfigurationDetail(2);
		$detailLastModify = $cConfiguration ->CConfigurationDetail(3);
		$col_limit = $cConfiguration ->CConfigurationDetail(5);
		$pager_limit = $cConfiguration ->CConfigurationDetail(6);
		$mainContent = '<div id="content2">
							<span style="font-size:10px;color:#FF0000;font-weight:bold;font-family:Arial, Helvetica, sans-serif">'.$notification.'</span>
                        	<table border="0" width="90%" style="position:relative" align = "center" >';
		
		$mainContent .='<tr><td width="30%"> Total Views Of the Website </td><td>'.$numOfView['value'].' </td></tr>';					
		$mainContent .='<tr><td width="30%"> Time Now: </td><td>'.$curDay.' </td></tr>';
		$mainContent .='<tr><td width="30%">Last Login: </td><td>'.date( 'h:i:s d-m-Y' ,$detailLastLogin['value']).'</td></tr>';	
		$mainContent .='<tr><td width="30%">Last Modify: </td><td>'.date( 'h:i:s d-m-Y' ,$detailLastModify['value']).'</td></tr>';
		
		$mainContent .='<tr><td width="30%">Column limit: </td><td>'.$col_limit['value'].'</td></tr>';	
		$mainContent .='<tr><td width="30%">Pager limit: </td><td>'.$pager_limit['value'].'</td></tr>';	
		$mainContent.='</table></div>';
	}
	
	echo $mainContent;
?>

